/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.cell;

import gui.data.ITrackEventData;
import java.awt.Color;
import java.awt.Component;
import java.text.SimpleDateFormat;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 * A Cell Renderer that represents an event in a JList
 * 
 * @author Pascal
 */
public class TrackEventCellRenderer extends javax.swing.JPanel implements ListCellRenderer<ITrackEventData> {

    /**
     * Creates new form TrackEventCellRenderer
     */
    public TrackEventCellRenderer() {
        initComponents();
        
        formatter = new SimpleDateFormat("HH:mm 'Uhr'");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelIcon = new javax.swing.JLabel();
        labelName = new javax.swing.JLabel();
        labelTime = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setMinimumSize(new java.awt.Dimension(10, 60));
        setLayout(new java.awt.CardLayout(5, 15));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setOpaque(false);
        jPanel1.setLayout(new java.awt.BorderLayout(10, 0));

        labelIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/resources/picture.png"))); // NOI18N
        jPanel1.add(labelIcon, java.awt.BorderLayout.LINE_START);

        labelName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelName.setText("Saarschleife");
        jPanel1.add(labelName, java.awt.BorderLayout.CENTER);

        labelTime.setText("10:48 Uhr");
        jPanel1.add(labelTime, java.awt.BorderLayout.LINE_END);

        add(jPanel1, "card5");
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelIcon;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelTime;
    // End of variables declaration//GEN-END:variables
    private SimpleDateFormat formatter;
    
    @Override
    public Component getListCellRendererComponent(JList<? extends ITrackEventData> list, ITrackEventData value, int index, boolean isSelected, boolean cellHasFocus) {
        
        switch (value.getEventType()) {
            case Image:
                labelIcon.setIcon(new ImageIcon(getClass().getResource("/gui/resources/picture.png")));
                break;
            case Text:
                labelIcon.setIcon(new ImageIcon(getClass().getResource("/gui/resources/text_dropcaps.png")));
                break;
            case Video:
                labelIcon.setIcon(new ImageIcon(getClass().getResource("/gui/resources/film.png")));
                break;
        }
        
        labelName.setText(value.getEventName());
        labelTime.setText(formatter.format(value.getEventDate().getTime()));
        
        if (isSelected) {
            setBackground(new Color(171, 203, 255));
        }
        else {
            if (index % 2 == 0) {
                this.setBackground(new Color(250, 250, 250));
                //jPanel1.setBackground(new Color(250, 250, 250));
            }
            else {
                this.setBackground(new Color(255, 255, 255));
                //jPanel1.setBackground(new Color(255, 255, 255));
            }
        }
        
        
        
        return this;
    }
}
